<div class='page_head'>
<h2><%="All messages".t%> </h2>
</div>

<%if @messages.size == 0%>

 <div class=tour>
  <%if (not @project.use_permission or @project.use_permission.nil?) or (@project.use_permission and (@project.msg_categories.select{|c| @cur_user.has_permission?("prj_" + @project.id.to_s + "_#{c.id}_msg_cat_new")}.size > 0 or @cur_user.has_permission?("prj_" + @project.id.to_s + "_unc_msg_cat_new")))%>
    <h2><%=link_to "Post the first message for this project".t,new_project_message_path(params[:project_id])%></h2>
  <%end%>
   <%="Post messages, share project updates, ask questions, communicate.".t%>
 </div>
 <%=feature'message'%>
 <%=feature'new_message'%>

<%else%>

<% for message in @messages %>
  
  <%if flash[:notice] == message.id %>
   <div class="message" id=fade> 
     <script> waittofade(); </script>
  <%else%>
   <div class="message">
  <%end%>
    <span class="private_label float_right"><%="Private".t if message.private%></span>
    <h2>
       <%=image_tag"paperclip.gif" if message.files.size > 0 %>
        <%=link_to message.name,project_message_path(message.project,message)%> 
    </h2>
    <div class="msg_body">
      <%=CGI.unescapeHTML(message.body.to_s)%>
    </div>
    <div class='msg_prop'>
     <%="by".t%> <%=message.user.name%>
     <%="in".t + " " + link_to(message.category.name,project_msg_in_category_path(@project.id,message.category.id)) if message.category%>
     <%="on".t + " " +  message.created_at.strftime('%Y-%m-%d %H:%M')%> 
     | <%=link_to (message.comments.size == 0 ? "Post the first comment".t : message.comments.size.to_s + " comments".t),project_message_path(message.project.id,message) + "#comment"%>
     <%="|" + link_to("Edit".t,edit_project_message_path(message.project.id,message),:class=>'admin') if @cur_user.id == message.user.id or (@project.use_permission and (@cur_user.have_power?(@project) or @cur_user.has_permission?("prj_" + @project.id.to_s + "_" + (message.category_id.to_i > 0 ? message.category_id.to_s : "unc") + "_msg_cat_edit")))%> 
   <%=link_to image_tag("trash.gif",:border=>0),project_message_path(params[:project_id],message),:confirm=>'Are you sure?',:method=>'delete',:class=>'admin' if @cur_user.have_power?(@project) or message.user_id == @cur_user.id%>

    </div>
   </div>
<% end %>

<div class="float_right page">
  <%if @message_pages.length > 1%>
   Pages:
  <%end%>
  <% if params[:category_id] %>
   <%=pagination_links @message_pages,:params=>{:controller=>'redirect',:url=> project_msg_in_category_path(params[:project_id],params[:category_id])}%>
  <%else%>
    <%= link_to '<<', project_messages_path(params[:project_id]) + "?page=" + @message_pages.current.previous.to_i.to_s if @message_pages.current.previous %>
   <%=pagination_links @message_pages%>
    <%= link_to '>>', project_messages_path(params[:project_id]) + "?page=" + @message_pages.current.next.to_i.to_s if @message_pages.current.next%>
  <%end%>
</div>
<%end%>
